package com.qidianit.task.controller;

import com.qidianit.task.pojo.Task;
import com.qidianit.task.service.TaskService;
import com.qidianit.task.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 钟思念
 * @Company
 * @Description
 * @Time 2024/9/10 14:40
 */
@RestController
@CrossOrigin
@RequestMapping("/task")
public class TaskController {
    @Autowired
    private TaskService taskService;
    /**
     * 通过projectId和parentId查询任务列表
     * @param projectId
     * @param parentId 0 说明是查询一级任务
     * @return
     */
    @GetMapping("/list")
    public QdResult list(String projectId, Long parentId){
        return taskService.list(projectId,parentId);
    }
    //保存新增的任务
    @PostMapping("/save")
    public QdResult save(@RequestBody Task task){
        return taskService.save(task);
    };
    //获取任务的详情
    @GetMapping("/get")
    public QdResult get(Long taskId){
        return taskService.queryById(taskId);
    }
    //保存编辑的任务内容
    @PostMapping("/update")
    public QdResult update(@RequestBody Task task){
        return taskService.updateByEdit(task);
    }
    //行按钮的删除功能
    @PostMapping("/delete")
    public QdResult delete(@RequestBody Task task){
        return taskService.deleteTask(task);
    };
    //统计我的待办任务
    @GetMapping("/myContinueTask")
    public QdResult myContinueTask(@RequestParam Long userId){
        return taskService.myContinueTask(userId);
    }
    //统计我的完成的任务
    @GetMapping("/myOverTask")
    public QdResult myOverTask(@RequestParam Long userId){
        return taskService.myOverTask(userId);
    }
    //通过TaskId删除Task
    @GetMapping("/deleteByTaskId")
    public QdResult deleteByTaskId(@RequestParam Long taskId){
        return taskService.deleteTaskByTaskId(taskId);
    }
    //通过projectId查询该项目的数量
    @GetMapping("/taskByProjectId")
    public QdResult taskByProjectId(@RequestParam String projectId){
        return taskService.queryTaskByProjectId(projectId);
    }
}
